﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using CashFlow.Db.Repository;
using CashFlow.Db.Entity;

namespace CashFlow.Db.Implement.Repository
{
    public class UserInfoRepository : Repository<UserInfoEntity>, IUserInfoRepository
    {
        public bool IsExistPhone(string phone)
        {
            using (var db = GetDb())
            {
                return db.Queryable<UserInfoEntity>().Where(x => x.Phone == phone).Count() > 0;
            }
        }

        public bool IsExistInvitationCode(string code)
        {
            using (var db = GetDb())
            {
                return db.Queryable<UserInfoEntity>().Where(x => x.ReferenceInvitationCode == code).Count() > 0;
            }
        }

        public UserInfoEntity QueryByReferenceInvitationCode(string code)
        {
            using (var db = GetDb())
            {
                var entity = db.Queryable<UserInfoEntity>().Where(x => x.InvitationCode == code).First();
                return entity;
            }
        }
    }
}
